package com.cxh.dao.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import com.common.dao.BaseDao;
import com.common.entity.A_evaluate;
import com.cxh.dao.A_evaluateDao;

public class A_evaluateDaoImpl extends BaseDao<A_evaluate> implements A_evaluateDao {

	@Override
	/**
	 * ע�⣺ʹ��ʱmp��key����Ϊ���������
	 * ����Ϊ������Բ����������
	 * Integer eva_id,      String eva_msg, Integer eva_score,
	   Integer customer_id, Date eva_date,  Integer issee
	 */
	public List<A_evaluate> findByCondition(Map<String, Object> mp) {
		List<Object> pList = new ArrayList<Object>();
		StringBuffer sb = new StringBuffer(" select * from A_evaluate where 1=1 ");
		if(!(mp==null||mp.size()<1))
			for(Entry<String, Object> et:mp.entrySet()){
				sb.append("and "+et.getKey()+" = ? ");
				pList.add(et.getValue());
			}
		return findBySql(sb.toString(), pList.toArray());
	}

	@Override
	public A_evaluate findById(int id) {
		String sql = " select * from A_evaluate where eva_id = ? ";
		Object[] obj = {id};
		List<A_evaluate> lg = findBySql(sql, obj);
		return (lg!=null&&lg.size()>0)?lg.get(0):null;
	}

	@Override
	/**
	 * ע�⣺ʹ��ʱmp��key����Ϊ���������
	 * ����Ϊ������Բ����������
	 * Integer eva_id,      String eva_msg, Integer eva_score,
	   Integer customer_id, Date eva_date,  Integer issee
	 */
	public int updateA_evaluate(Map<String, Object> mp) {
		String sql = "update A_evaluate set eva_msg=?, eva_score=?, customer_id=?, eva_date=?, "+
				"issee=? where eva_id=?";
		Object[] objs = {mp.get("eva_msg"),mp.get("eva_score"),mp.get("customer_id"),mp.get("eva_date"),
				mp.get("issee"),mp.get("eva_id")};
		return executeUpdate(sql, objs);
	}

	@Override
	public int deleteA_evaluate(int id) {
		String sql = "delete from A_evaluate where EVA_ID=?";
		Object[] objs = {id};
		return executeUpdate(sql, objs);
	}

	@Override
	/**
	 * ע�⣺ʹ��ʱmp��key����Ϊ���������
	 * ����Ϊ������Բ����������
	 * Integer eva_id,      String eva_msg, Integer eva_score,
	   Integer customer_id, Date eva_date,  Integer issee
	 */
	public int addA_evaluate(Map<String, Object> mp) {
		String sql = "insert into A_evaluate values(SEQ_A_evaluate.nextval,?,?,?,?,?)";
		Object[] objs = {mp.get("eva_msg"),mp.get("eva_score"),mp.get("customer_id"),mp.get("eva_date"),
				mp.get("issee")};
		return executeUpdate(sql, objs);
	}

	@Override
	public A_evaluate getEntity(ResultSet rs) {
		A_evaluate e = new A_evaluate();
		try {
			e.setCustomer_id(rs.getInt("customer_id"));
			e.setEva_date(rs.getDate("eva_date"));
			e.setEva_id(rs.getInt("eva_id"));
			e.setEva_msg(rs.getString("eva_msg"));
			e.setEva_score(rs.getInt("eva_score"));
			e.setIssee(rs.getInt("issee"));
			return e;
		} catch (SQLException e1) {
			e1.printStackTrace();
		}
		return null;
	}

}
